import uiautomator2 as u2
import time
import re
import os, subprocess, random
import threading
import pyperclip
import datetime
import json
import sys
from decimal import Decimal

adb_path = "C:\\android-sdk-windows\\platform-tools\\"



def get_devices(self):
    '''获取已经链接的手机id'''
    devices_info = os.popen('''%sadb.exe devices -l''' % adb_path).read()
    splited_devices = devices_info.split('\n')[1][0:]
    device_id = re.findall("(\w+) +device product", splited_devices)[0]
    print(device_id)
    return device_id


def reboot(d):
    # 重启
    os.system('''%sadb.exe kill-server'''%adb_path)
    time.sleep(3)
    print(d)
    x='''%sadb.exe -s %s reboot'''%(adb_path,d)
    os.system(x)

def connect_devices(device_id):
    d = u2.connect(device_id)
    print(d)
    return d


